<?php

namespace backend\models\user;

use Yii;

/**
 * This is the model class for table "{{%edu_teacher_position}}".
 *
 * @property integer $position_id
 * @property string $position_name
 * @property integer $is_show
 * @property integer $position_addtime
 * @property integer $position_sort
 */
class TeacherPosition extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%teacher_position}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
			[['position_name'], 'required'],
            [['is_show', 'position_addtime', 'position_sort'], 'integer'],
			[ 'position_addtime','default', 'value' =>time(),],
            [['position_name'], 'string', 'max' => 20]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'position_id' => '职位id',
            'position_name' => '职位名称',
            'is_show' => '是否显示',
            'position_addtime' => '添加时间',
            'position_sort' => '排序',
        ];
    }
	/**
	* 显示职位
	*/
	public function PositionSel()
    {
		return $this->find()
					->orderBy(['position_sort'=>SORT_DESC])
					->all();
	}
	/**
	* 前台显示职位
	*/
	public function Position()
    {
		return $this->find()
					->where(['is_show' => '1'])
					->orderBy(['position_sort'=>SORT_DESC])
					->all();
	}
	/**
	* 显示一条职位
	*/
	public function PositionFind($position_id)
    {
		return $this->find()
					->where(['=','position_id',$position_id])
					->asArray()
					->one();
	}
}
